package http

type ResultCode int

const (
	RESULT_CODE_SUCCESS     ResultCode = 0
	RESULT_CODE_UNKNOW_FAIL ResultCode = 1 //未知错误
)

type JsonResult struct {
	Code ResultCode `json:"code"`
	Msg  string     `json:"msg"`
	Data any        `json:"data"`
}

func JsonSuccess(data any) *JsonResult {
	return &JsonResult{
		Code: RESULT_CODE_SUCCESS,
		Msg:  "success",
		Data: data,
	}
}

func JsonFail(msg string, code ResultCode) *JsonResult {
	return &JsonResult{
		Code: code,
		Msg:  msg,
		Data: nil,
	}
}

// 位置失败错误
func JsonUnknownFail(msg string) *JsonResult {
	return JsonFail(msg, RESULT_CODE_UNKNOW_FAIL)
}
